package com.commerce.weather.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.commerce.weather.Entity.City;
import com.commerce.weather.R;

import java.util.List;

public class MyTextAdapter extends BaseAdapter {
    private static final String TAG = "MyListAdapter";
    private List<City.ResultBean> listData;
    private Context context;
    public MyTextAdapter(Context context, List<City.ResultBean> listData) {
        this.listData=listData;
        this.context = context;
    }

    @Override
    public int getCount() {
        return listData.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }



    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view==null){
            view =LayoutInflater.from(context).inflate(R.layout.layout_text,null);
            viewHolder = new ViewHolder();
            viewHolder.cityText = view.findViewById(R.id.lt_text);
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.cityText.setText(listData.get(i).getProvince()+"——"+
                listData.get(i).getCity()+"——"+
                listData.get(i).getDistrict());
        return view;
    }

    private class ViewHolder {
        private TextView cityText;
    }
}
